<template>
  <div>
    <h2 @click="openKf">客服测试</h2>
    <h2 @click="openByU">客服测试-带用户信息</h2>
    <h2 @click="sendProduct">客服测试-发送商品信息</h2>
    <h2 @click="toKF2">客服测试-toKF2</h2>
  </div>
</template>

<script>
  export default {
    name: 'kf',
    //inject: ['reload'],
    data () {
      return {
        msg: 'Welcome to Your Vue.js App',
        shareMenu: [0, 1, 2, 3, 4],
        isSdkReady: false
      }
    },
    mounted () {
    },
    created () {
      this.init();

      ysf('onready', function () {
        //this.isSdkReady = true;
        //console.log('this.isSdkReady',this.isSdkReady);
      })
    },
    methods: {
      init(){
        (function (w, d, n, a, j) {
          w[n] = w[n] || function () {
            (w[n].a = w[n].a || []).push(arguments);
          };
          j = d.createElement('script');
          j.async = true;
          j.src ='https://qiyukf.com/script/db27a46d9ddfb5a8b234c3a6d049acbc.js?hidden=1';
          d.body.appendChild(j);
        })(window, document, 'ysf');



      },
      openKf(){
        //this.reload();
        //window.openKf();
        ysf('open');
      },
      openByU(){
        this.reload();
        const user = {
          uid: "123456789",      // 用户Id
          name: 'test',          // 用户名称
          email: 'test@163.com', // 用户邮箱
          mobile: '13888888888'  // 用户电话
        };
        //window.openByUser(user);
        ysf('config', {
          uid: user.uid,
          name: user.name,
          email: user.email,
          mobile: user.mobile,
          success: function(){
            ysf('open');
          },
          error: function(){
            // handle error
          }
        });
      },
      sendProduct(){
        this.reload();
        const product = {
          show : 1, // 1为打开， 其他参数为隐藏（包括非零元素）
          title : '汽车方向盘套16寸',
          desc : '汽车方向盘套16寸汽车方向盘套16寸',
          picture : 'https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268%3Bg%3D0/sign=2ee3343f72cf3bc7e800caeae93bdd9c/bf096b63f6246b6045d97a46e9f81a4c510fa229.jpg',
          note : '货号：223464654654564'
        };

        //window.sendProduct(product);

        ysf('product', {
          show : 1, // 1为打开， 其他参数为隐藏（包括非零元素）
          title : product.title,
          desc : product.desc,
          picture : product.picture,
          note : product.note,
          //url : product.url,
          //tags: product.tags,
          success: function(){
            ysf('open');
          },
          error: function(){
            // handle error
          }
        });

      },
      toKF2(){
        this.$router.push('/kf2');
      }
    }
  }
</script>

<style scoped>

</style>
